/*
 * Sergii Donchenko, Kiev 2012
 * Calendar
 * Program to Calendar date
 */
 import java.util.*;
	
 public class Calendar
 {	
	public static void main(String[] arg)
	{
		Scanner in = new Scanner (System.in);
		
		System.out.print("Input day (DD): ");
		int dayValue = in.nextInt();
		System.out.print("Input month (MONTH): ");
		String monthValue = in.next(); 
		System.out.print("Input year (YYYY): ");
		int yearValue = in.nextInt();
		
		int month = 0;
		if (monthValue.equals("January")) 
        	month = 1;
        if (monthValue.equals("February")) 
        	month = 2;
		if (monthValue.equals("March")) 
			month = 3;
        if (monthValue.equals("April")) 
        	month = 4;
        if (monthValue.equals("May")) 
        	month = 5;
        if (monthValue.equals("June")) 
        	month = 6;
        if (monthValue.equals("July"))
        	month = 7;
        if (monthValue.equals("August")) 
        	month = 8;
        if (monthValue.equals("September")) 
        	month = 9;
        if (monthValue.equals("October")) 
        	month = 10;
        if (monthValue.equals("November")) 
        	month = 11;
        if (monthValue.equals("December")) 
        	month = 12;
        
        if (month == 0){
        	System.out.print ("Please write correct month, such as ''May'' ");
            return;
        }
        if (dayValue < 1){
        	System.out.print ("Please write correct day");
        	return;
        }
		else {
			if (month == 1 || month == 3 || month == 5 || month == 7|| month == 8 || month == 10 || month == 12) {
				if (dayValue > 31){
					System.out.print ("Please write correct day of month");
					return;
				}
			}
			else {
				if (dayValue > 30){
					System.out.print ("Please write correct day of month");
					return;
				}
			}
	   }
       if ((yearValue % 4 == 0 && yearValue % 100 != 0 || yearValue % 400 == 0)) { // formula of a leap year
    	   if (month == 2 && dayValue > 29){
        		System.out.print ("Sorry, failure rule of leap year");
        		return;
        	}
        }
        else {
        	if (month == 2 && dayValue > 28){
        		System.out.print ("Sorry, failure rule of leap year");
        		return;
        	}
        }
        if (yearValue < 0){
        	System.out.print ("Please correct day of month");
        	return;
                }
           
        int a = (14 - month) / 12;
		int y = yearValue - a;
		int m = month + 12 * a - 2;
		int getDayOfWeek = ((7000 + (dayValue + y + y / 4 - y / 100 + y / 400 + (31 * m) / 12)) % 7) ; // formula of week day
		
        switch (getDayOfWeek) {
               	case 0:
                    System.out.println("Sunday");
                    break;
                case 1:
                    System.out.println("Monday");
                    break;
                case 2:
                    System.out.println("Tuesday");
                    break;
                case 3:
                    System.out.println("Wednesday");
                    break;
                case 4:
                    System.out.println("Thursday");
                    break;
                case 5:
                    System.out.println("Frieday");
                    break;
                case 6:
                	System.out.println("Saturday");
                	break;
        }       
	}
 }